<?php
header('Content-type: application/json');
include_once 'Service.php';

$functionName = $_POST['functionName'];

if($functionName == 'addTask'){
         
	$category = $_POST['category'];
	$action   = $_POST['action'];
	$date    = $_POST['date'];
	$duration = $_POST['duration'];
	$comment  = $_POST['comment'];
	 
	$service = new Service();  //
	echo $service->addTask($category,$action,$date,$duration,$comment);
    
}elseif ($functionName == 'deleteTask'){
	
	$idTask = $_POST['idTask'];
	$service=new Service();
	
	echo $service->deleteTask($idTask);

}

elseif ($functionName == 'addUser'){
	
	$name = $_POST['name'];
	$firstName = $_POST['firstName'];
	$userName = $_POST['user'];
	$pass = $_POST['pass'];
	
	$service=new Service();
	echo $service->addUser($name,$firstName,$userName,$pass);
	
}elseif ($functionName == 'deleteUser'){

	$idUser = $_POST['idUser']; 

	$service=new Service();
	echo $service->deleteUser($idUser);
	
}elseif ($functionName == 'getUsers'){

	$service = new Service();
	echo json_encode($service->getUsers());

}elseif ($functionName == 'getTasks'){

	$service = new Service();
	echo json_encode($service->getTasks());
}elseif ($functionName == 'getTasksForCalendar'){
	$end = $_POST['end'];
	$start = $_POST['start'];

	$service = new Service();
	echo json_encode($service->getTasksForCalendar($start,$end));		
}else
{	
	return null;
}